package com.lagou.config;


import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.HandlesTypes;
import java.util.Set;

@HandlesTypes({MySpringServletContainerInitializer.class})
public class MySpringServletContainerInitializer extends MyServlet implements  ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) {
        AnnotationConfigWebApplicationContext ac=new AnnotationConfigWebApplicationContext();
        //注册配置类
        ac.register(AppConfig.class);
        ac.refresh();

        //向servletContext容器加入DispatcherServlet
        ServletRegistration.Dynamic dynamic =servletContext.addServlet("app",super.getDispatcherServlet());
        dynamic.setLoadOnStartup(1);
        dynamic.addMapping("/app/*");
    }
}